phraseexpressfandomcom-20200213-history
COND -- Conditional if-then-else
The {#COND} command outputs text, depending on a condition. Specifically, if a condition is met (as specified in the '-if' clause), text in the '-then' clause is output. If not met, text in the '-else' clause is output. The real power of a {#COND} command is in deciding the NAME of a phrase to execute. The simplest example, where {#COND} simply outputs text (all examples are intended to be called in your text editor): mainbasic {#COND -if 3 < 1 -then three-is-less-than-one -else three-is-not-less-than-one} Call 'zMain' and this is output: three-is-not-less-than-one Importantly, ALL phrases in the '-then' and '-else' clauses are executed--regardless the condition. So although calling mainwcall results in the same output... mainwcall {#COND -if 3 < 1 -then {#insert z3lt1} -else {#insert z3nlt1}} z3lt1 three-is-less-than-one z3nlt1 three-is-not-less-than-one ...it is not ideal, since the all phrases in BOTH the '-then' and '-else' clauses are executed--the output of the '-then' clause is suppressed, but it is STILL executed. To demonstrate this, call mainwdbg: mainwdbg {#COND -if 3 < 1 -then {#insert z3lt1WDbg} -else {#insert z3nlt1WDbg}} z3lt1WDbg three-is-less-than-one{#MSGBOX -head DEBUG: z3lt1WDbg -text DEBUG: z3lt1WDbg} z3nlt1WDbg three-is-not-less-than-one{#MSGBOX -head DEBUG: z3nlt1WDbg -text DEBUG: z3nlt1WDbg} As expected, only three-is-not-less-than-one is output, but BOTH dialogs popup. ---- The real power of the {#COND} command comes in determining which phrase to execute. For example: maininins {#insert {#COND -if 3 < 1 -then z3lt1 -else z3nlt1}} This results in {#insert z3nlt1} and therefore: three-is-not-less-than-one Since only the phrase-name is generated by the {#COND} command, nothing extra is executed. ---- To conclude with a slightly-more realistic example: zYourNamePrompt {#INPUT -head Your name? -def Humphrey -single} mainnameltoe5 {#insert {#COND -if {#LENGTH {#insert zYourNamePrompt}} <= 5 -then zNameIsLTOE5Chars -else zNameIsGT5Chars}} zNameIsGT5Chars Your name, {#insert zYourNamePrompt}, has more than five characters. zNameIsLTOE5Chars Your name, {#insert zYourNamePrompt}, has exactly five, or less-than five characters. Call mainnameltoe5, and this is output: Your name, Humphrey, has more than five characters. ---- Here is an import text file for all the above examples: mainbasic {#COND -if 3 < 1 -then three-is-less-than-one -else three-is-not-less-than-one} mainbasic maininins {#insert {#COND -if 3 < 1 -then z3lt1 -else z3nlt1}} maininins mainnameltoe5 {#insert {#COND -if {#LENGTH {#insert zYourNamePrompt}} <= 5 -then zNameIsLTOE5Chars -else zNameIsGT5Chars}} mainnameltoe5 mainwcall {#COND -if 3 < 1 -then {#insert z3lt1} -else {#insert z3nlt1}} mainwcall mainwdbg {#COND -if 3 < 1 -then {#insert z3lt1WDbg} -else {#insert z3nlt1WDbg}} mainwdbg z3lt1 three-is-less-than-one z3lt1 z3lt1WDbg three-is-less-than-one{#MSGBOX -head DEBUG: z3lt1WDbg -text DEBUG: z3lt1WDbg} z3lt1WDbg z3nlt1 three-is-not-less-than-one z3nlt1 z3nlt1WDbg three-is-not-less-than-one{#MSGBOX -head DEBUG: z3nlt1WDbg -text DEBUG: z3nlt1WDbg} z3nlt1WDbg zNameIsGT5Chars Your name, {#insert zYourNamePrompt}, has more than five characters. zNameIsGT5Chars zNameIsLTOE5Chars Your name, {#insert zYourNamePrompt}, has exactly five, or less-than five characters. zNameIsLTOE5Chars zYourNamePrompt {#INPUT -head Your name? -def Humphrey -single} zYourNamePrompt To import these phrases: #Paste these lines in a new document. Save it as cond_example.px.txt #Open PhraseExpress #Drag cond_example.px.txt, from Windows Explorer, into your PhraseExpress folder heirachry. #When the "Select action for the dropped file" dialog appears, choose "Generate phrases for each line in the file" and click OK #In the "Generate phrases of the text file" dialog, in the drop-down, choose "Description - Delimiter - Phrase text - Delimiter - Autotext" and type TAB in the "Delimiter" textbox. Then click OK. #Close PhraseExpress ---- Aliteralmind (talk) 01:30, December 3, 2012 (UTC) Category:Specific Commands